package com.itheima.stock.common;

import com.itheima.stock.utils.IdWorker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @ClassName CommonConfig
 * @Description TODO
 * @Author Zack
 * @Date 2022/12/5 21:30
 * @Version 1.0
 */
@Configuration
public class CommonConfig {
    @Value("${IdWorker.workerId}")
    private long workerId;
    @Value("${IdWorker.datacenterId}")
    private long datacenterId;
    /**
     * 配置id生成器bean
     * @return
     */
    @Bean
    public IdWorker idWorker(){
        return new IdWorker(workerId, datacenterId);
    }
    @Bean
    public PasswordEncoder passwordEncoder() {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder;
    }
}
